package chatGUI;

import javax.swing.*;


/**
* MAin Frame: contains list of connected users, a window for the broadcast convestation 
*/
public class MainFrame extends javax.swing.JFrame {
	protected JLabel usersLabel;
	protected JList usersList;
	protected JLabel textLabel;
	protected JLabel convLabel;
	protected JTextArea textArea;
	protected JScrollPane textScroll;
	protected JTextArea convArea;
	protected JScrollPane convScroll;
	protected JButton logout;
	protected JButton sendbutton;

	/**
	* Constructor
	*/
		
	public MainFrame() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			GroupLayout thisLayout = new GroupLayout((JComponent)getContentPane());
			getContentPane().setLayout(thisLayout);
			setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
			//this.setLocationRelativeTo(null);
			this.setResizable(false);
			getContentPane().setForeground(new java.awt.Color(77,77,77));
			getContentPane().setBackground(new java.awt.Color(77,77,77));
			//ajout des scrollbars

			{
				textLabel = new JLabel();
				textLabel.setText("Your text");
				textLabel.setFont(new java.awt.Font("Andale Mono",1,14));
				textLabel.setForeground(new java.awt.Color(255,255,255));
			}
			{
				convScroll = new JScrollPane();
				{
					convArea = new JTextArea();
					convScroll.setViewportView(convArea);
					convArea.setEditable(false);
				}
			}
			{
				textScroll = new JScrollPane();
				{
					textArea = new JTextArea();
					textScroll.setViewportView(textArea);
				}
			}
			{
				ListModel usersListModel = 
						new DefaultComboBoxModel(
								new String[] {""});
				usersList = new JList();
				usersList.setModel(usersListModel);
				usersList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
				usersList.setBackground(new java.awt.Color(246,219,203));
			}
			{
				usersLabel = new JLabel();
				usersLabel.setFont(new java.awt.Font("Andale Mono",1,14));
				usersLabel.setForeground(new java.awt.Color(255,255,255));
				usersLabel.setText(usersList.getModel().getSize() + " online users");
			}
			{
				convLabel = new JLabel();
				convLabel.setText("Main Room");
				convLabel.setFont(new java.awt.Font("Andale Mono",1,26));
				convLabel.setForeground(new java.awt.Color(213,125,69));
			}
			{
				sendbutton = new JButton();
				sendbutton.setText("Send");
			}
			{
				logout = new JButton();
				logout.setText("Logout");
				logout.setSize(100, 38);
				logout.setBackground(new java.awt.Color(213,125,69));
			}
			thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
				.addContainerGap()
				.addGroup(thisLayout.createParallelGroup()
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addComponent(usersLabel, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)
				        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED))
				    .addComponent(convLabel, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE))
				.addGroup(thisLayout.createParallelGroup()
				    .addComponent(convScroll, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 392, GroupLayout.PREFERRED_SIZE)
				    .addComponent(usersList, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 392, GroupLayout.PREFERRED_SIZE))
				.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
				.addComponent(textLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
				.addGroup(thisLayout.createParallelGroup()
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addComponent(sendbutton, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE)
				        .addGap(32)
				        .addComponent(logout, 0, 30, Short.MAX_VALUE))
				    .addGroup(thisLayout.createSequentialGroup()
				        .addComponent(textScroll, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 0, Short.MAX_VALUE)))
				.addContainerGap());
			thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
				.addContainerGap()
				.addGroup(thisLayout.createParallelGroup()
				    .addComponent(textScroll, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 564, GroupLayout.PREFERRED_SIZE)
				    .addComponent(convScroll, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 564, GroupLayout.PREFERRED_SIZE)
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addComponent(convLabel, GroupLayout.PREFERRED_SIZE, 173, GroupLayout.PREFERRED_SIZE)
				        .addGap(391))
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addComponent(textLabel, GroupLayout.PREFERRED_SIZE, 82, GroupLayout.PREFERRED_SIZE)
				        .addGap(482)))
				.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
				.addGroup(thisLayout.createParallelGroup()
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addComponent(sendbutton, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 7, Short.MAX_VALUE)
				        .addComponent(logout, GroupLayout.PREFERRED_SIZE, 91, GroupLayout.PREFERRED_SIZE))
				    .addGroup(thisLayout.createSequentialGroup()
				        .addGap(0, 7, Short.MAX_VALUE)
				        .addGroup(thisLayout.createParallelGroup()
				            .addComponent(usersLabel, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 191, GroupLayout.PREFERRED_SIZE)
				            .addComponent(usersList, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 190, GroupLayout.PREFERRED_SIZE))))
				.addContainerGap());
			pack();
			this.setSize(800, 600);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

}
